﻿Imports System.Windows.Forms
Imports IconPrinting.ICONPrinting
Imports Microsoft.Win32
Public Class SettingPrinter
    Inherits baseForm
    Private lstPrinter As clsGetPrinter
    Private Sub InitComboPrinter()
        lstPrinter = New clsGetPrinter
        Dim sLst() As String = lstPrinter.ListPrinter.Split(";")
        cboPrinter.Items.Clear()
        For i As Integer = 0 To sLst.Length - 1
            cboPrinter.Items.Add(sLst(i).ToString)
        Next
        'ComboBox1.Items.Clear()
        'For i As Integer = 0 To sLst.Length - 1
        '    ComboBox1.Items.Add(sLst(i).ToString)
        'Next

    End Sub

    Private Sub FillFormByRegistry()
        'cboPrinter.Text = clsReg.RetrieveKey("PrinterName")
        'txtLeftMargin.Text = clsReg.RetrieveKey("LeftMargin")
        'txtTopMargin.Text = clsReg.RetrieveKey("TopMargin")
        cboPrinter.Text = My.Settings.PrinterName
        txtLeftMargin.Text = My.Settings.LeftMargin
        txtTopMargin.Text = My.Settings.TopMargin

        'ComboBox1.Text = My.Settings.PrinterNameID
        'TextBox2.Text = My.Settings.LeftMarginID
        'TextBox1.Text = My.Settings.TopMarginID
    End Sub


    Public Function ButtonSaveClick(ByVal typeAction As String) As Integer
        If ValidasiEntry() Then
            My.Settings.PrinterName = cboPrinter.Text
            My.Settings.LeftMargin = txtLeftMargin.Text
            My.Settings.TopMargin = txtTopMargin.Text
            Return 1
        End If
    End Function

    Private Function ValidasiEntry() As Boolean
        If Not IsNumeric(txtLeftMargin.Text) Then
            MessageBox.Show("Left margin harus dalam numerik !")
            Return False
        End If

        If Not IsNumeric(txtTopMargin.Text) Then
            MessageBox.Show("Top margin harus dalam numerik !")
            Return False
        End If

        Return True
    End Function

    'Private Function ValidasiEntryID() As Boolean
    '    If Not IsNumeric(TextBox2.Text) Then
    '        MessageBox.Show("Left margin harus dalam numerik !")
    '        Return False
    '    End If

    '    If Not IsNumeric(TextBox1.Text) Then
    '        MessageBox.Show("Top margin harus dalam numerik !")
    '        Return False
    '    End If

    '    Return True
    'End Function

    Private Sub SettingPrinter_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        InitComboPrinter()
        FillFormByRegistry()
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If ValidasiEntry() Then
            My.Settings.PrinterName = cboPrinter.Text
            My.Settings.LeftMargin = txtLeftMargin.Text
            My.Settings.TopMargin = txtTopMargin.Text
            My.Settings.Save()
        End If
    End Sub

    'Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
    '    If ValidasiEntryID() Then
    '        My.Settings.PrinterNameID = ComboBox1.Text
    '        My.Settings.LeftMarginID = TextBox2.Text
    '        My.Settings.TopMarginID = TextBox1.Text
    '        My.Settings.Save()
    '    End If
    'End Sub
End Class
